import {getBaseCategoryList} from '@/api/product'
import {getLikeListData} from '@/api/product'
export const product = {
    namespaced:true,
    state(){
        return {
            categoryList:[],
            // 猜你喜欢的商品数据
            likeList:[],
            // 猜你喜欢的商品数据的总页数
            likePageSum:1,
        }
    },
    mutations:{
        UP_CATEGORY_LIST(state,payload){
            state.categoryList = payload
        },
        UP_LIKELIST_AND_PAGESUM(state,payload){
            state.likeList = payload.likeList;
            state.likePageSum = payload.pageSum;
        }
    },
    actions:{
        async getBaseCategoryListAsync(context,limit=15){
            console.log(context);
            if(context.state.categoryList.length>0) return 
            const res = await getBaseCategoryList();
            context.commit("UP_CATEGORY_LIST",res.data.data.slice(0,limit))
            
        },
        // async getLikeListDataAsync(){
        //     const res = await getLikeListData()
        //     console.log(res,'ffff');
        // }
        getLikeListDataAsync({commit},{pageNo,pageSize=6}){
            new Promise((resolve, reject) => {
                resolve(getLikeListData(pageNo,pageSize))
            }).then(
                response => {
                    console.log(response);
                    commit('UP_LIKELIST_AND_PAGESUM',res)
                },
                error => {
                    return error
                }
            )
        }
    }
}



